#include "ath.h"

char * 
ath_cookie_getval(request_rec *r, const char *name)
{
    const char *cookie = NULL;
    const char *value = NULL;
    char *cbuf = NULL;

    /* adapted from apache mod_usertrack httpd-2.0.47 */
    if ((name) && (cookie = apr_table_get(r->headers_in, "Cookie")))
      {
	  if ((value = ap_strstr_c(cookie, name))) 
	    {
		char *cend;
		/* Skip over the '=' */
		value += strlen(name) + 1;  
		/* Ignore anything after a ; */		
		cend = strchr(value, ';');
		cbuf = apr_pstrndup(r->pool, value, 
				    cend ? cend - value : strlen(value));
		ap_unescape_url(cbuf);
		
	    }
      }
    return cbuf;
}
